<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--准备好一个"容器"-->

<div id="test"></div>

<script type="text/javascript">
    let arr1 = [1, 3, 5, 6, 9];
    let arr2 = [2, 4, 6, 8, 10];
    //作用1：展开一个数组
    console.log(...arr1);
    console.log(arr1);

    //作用2：链接一个数组
    let arr3 = [...arr1, ...arr2];

    //作用3：函数传参
    function sum(...numbers) {
        return  numbers.reduce((previousValue, currentValue) => {
            return previousValue + currentValue;
        });
    }

    console.log(sum(arr1));


    //作用4：构造字面量对象时展开语法(复制对象)
    let person={name:'Jerry',age:123};
    let person2 = person;
    let person3 = {...person};
    console.log("未修改前:");
    console.log("person",person);
    console.log("person2",person2);
    console.log("person3",person3);
    //console.log(...person);//错误，三点展开符不能展开对象
    person2.name='Tom';
    console.log("修改后:");
    console.log("person",person);
    console.log("person2",person2);
    console.log("person3",person3);


    //作用5：合并
    let person4 = {...person,name:'Kitty',address:"火星"};
    console.log("person4",person4);
</script>

</body>
</html>
